package com.ywgt.controller;

import com.github.pagehelper.Page;
import com.ywgt.pojo.Collect;
import com.ywgt.service.CollectService;
import com.ywgt.util.ResponseUtil;
import io.swagger.annotations.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/admin/collect")
@ApiModel("收藏管理")
public class CollectController {
    @Autowired
    CollectService collectService;
    /**
     * page: 1,
     * limit: 20,
     * userId: undefined,
     * valueId: undefined,
     * sort: 'add_time',
     *  order: 'desc'
     * @return
     */
    @GetMapping("/list")
    public Object getCollects(Integer userId, Integer valueId, @RequestParam(required = false,defaultValue = "1") int page,
                              @RequestParam(required = false,defaultValue = "10") int limit,
                              @RequestParam(required = false,defaultValue = "add_time") String sort,
                              @RequestParam(required = false,defaultValue = "desc") String order){
        Page<Collect> collects=collectService.getCollects(userId,valueId,page,limit,sort,order);
        List<Collect> collectList = collects.getResult();
        long total = collects.getTotal();
        Map<String, Object> data = new HashMap<>();
        data.put("total", total);
        data.put("items", collectList);
        return ResponseUtil.ok(data);
    }
}
